// let today = new Date();
// let today_year_month_day = `${today.getFullYear()}` + `-` + `${today.getMonth()+1}`.padStart(2, '0') + `-` +
// 	`${today.getDate()}`.padStart(2, '0');
// let tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000 * 1)); //明天
// let tomorrow_year_month_day = `${tomorrow.getFullYear()}` + `-` + `${tomorrow.getMonth()+1}`.padStart(2, '0') + `-` +
// 	`${tomorrow.getDate()}`.padStart(2, '0');

import {
	resources_public
} from '@/common/api.js';

export default {
	data() {
		return {
			datetimePickerMaxDate:new Date().getTime(),
			datetimePickerMinDate:new Date().getTime() - (24 * 60 * 60 * 1000 * 1 * 365 * 40),
			isLogin: this.$store.getters.get_isLogin,
			userInfo: this.$store.getters.get_userInfo,
			formLabelStyle:{
				fontSize: '24upx',
				lineHeight: '34upx',
				color:"#150A33",
				marginBottom:'7upx',
			},
			inputCustomStyle: {
				backgroundColor: '#ffffff',
				padding: '16upx',
				borderRadius: '16upx',
				fontSize: '24upx',
				boxShadow: '0px 8upx 124upx 0px rgba(153, 171, 198, 0.18)'
			}
		}
	},
	computed:{
		sid(){
			return this.$store.getters.get_sid
		},
		ascriptionUserId(){
			return this.$store.getters.get_ascriptionUserId
		}
	},
	filters: {
		
	},
	methods: {
		upx2px(num) {
			return uni.upx2px(num)
		},
		momentTZ(dateStr, format) {
			if (!dateStr) {
				return ''
			}
			if (!format) {
				format = 'YYYY-MM-DD HH:mm:ss';
			}
			// console.log(this.$moment.tz.guess());
			let new_dateStr = this.$momentTZ(dateStr).tz("Asia/Shanghai").format(format);
			return new_dateStr
		},
		formatDatetime(d) {
			// console.log(d);
			if(!d){
				return '';
			}
			let today = new Date(d);
			let _year_month_day = `${today.getFullYear()}` + `-` + `${today.getMonth()+1}`.padStart(2, '0') + `-` +
				`${today.getDate()}`.padStart(2, '0');
			return _year_month_day
		},
		// 图片线上路径
		getImgSrc(src) {
			if(!src){
				return '';
			}
			let baseUrl = 'http://192.168.1.75:8701/v1/resources/';
			return baseUrl + src;
		},
		// 富文本样式
		parseTagStyle() {
			return {
				'ul': 'padding-left:0;list-style:none;margin-left:0;margin-right:0',
				'ol': 'padding-left:0;list-style:none;margin-left:0;margin-right:0'
			}
		},
		// 跳转
		nav(url, type) {
			try {
				uni.$u.route({
					url: url,
					type: type || 'navigateTo'
				})
			} catch (e) {
				console.log(e);
			}
		},
		navSid(url, type){
			if (this.$store.getters.get_sid) {
				this.nav(url, type);
			} else {
				this.$store.dispatch('modal', '请先完成个人信息').then(() => {
					this.nav('/pages/information/information');
				}).catch(() => {
				
				})
			}
		},
		navBack(){
			uni.$u.route({
				type: 'navigateBack'
			})
		},
		// 是否登录跳转
		navLogin(url, type) {
			if (this.$store.getters.get_isLogin) {
				this.nav(url, type);
			} else {
				uni.reLaunch({
					url: '/pages/login/login'
				});
			}
		},
		// 下载文件并打开
		openFile(url) {
			uni.downloadFile({
				url: url,
				// url: '/attachment/images/1/2022/06/uRzd1I11EPoELer1YG6451aO1YL5EA.docx',
				success: function(res) {
					var filePath = res.tempFilePath;
					uni.openDocument({
						filePath: filePath,
						showMenu: true,
						success: function(res) {
							console.log('打开文档成功');
						}
					});
				}
			});
		},
		getStatusBarHeight() {
			const res = uni.getSystemInfoSync();
			if (res.platform === 'ios') {
				return 44 + res.statusBarHeight;
			} else if (res.platform === 'android') {
				return 48 + res.statusBarHeight;
			} else {
				return 0;
			}
		},
		//获取可视区域高度
		getClineHeight() {
			const res = uni.getSystemInfoSync();
			let clientHeight = res.windowHeight;
			return clientHeight;
		},
		toObj(data, key) {
			let obj = {};
			data.forEach(v => {
				obj[v[key]] = v;
			});
			return obj;
		},
		uniChooseImage(count){
			return new Promise(function(resolve, reject) {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'],
					sourceType: ['album'], //从相册选择
					success: function (res) {
						let url;
						if(count == 1){
							url = res.tempFilePaths[0];
						}else{
							url = res.tempFilePaths;
						}
						resolve(url);
					},
					fail: function(err) {
						reject(err);
					}
				});
			});
		},
		uploadFilePromise(url) {
			uni.showLoading({
				title: 'uploading'
			});
			return resources_public(url, {}).then((res) => {
				// console.log(res);
				uni.hideLoading();
				return res.data
			})
			// return new Promise((resolve, reject) => {
			// 	let a = uni.uploadFile({
			// 		url: 'https://zadev.slyspd.com/api/common/upload',
			// 		filePath: url,
			// 		name: 'file',
			// 		formData: {
			// 			sign: "38b78d9d26244549c58946c9c54a11bd",
			// 			token: "0566518b-5c7d-4f30-a792-65f29958797b"
			// 		},
			// 		success: (res) => {
			// 			// console.log(res);
			// 			setTimeout((res) => {
			// 				resolve(res.data.data)
			// 			}, 1000)
			// 		}
			// 	});
			// })
		}
	}
}